﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.CharmManager.Client.Interface;

namespace ZhimeiSoft.CharmManager.Client.Forms
{

    public partial class CustomInfo : BaseUserControl
    {   
        /// <summary>
        /// 会员信息
        /// </summary>
        private DataTable dtCustomInfo = null;
        /// <summary>
        /// 设置控件数据源
        /// </summary>
        public DataTable CustomInfoData
        {
            get
            {
                return dtCustomInfo;
            }
            set
            {
                if (value != null)
                {
                    this.dtCustomInfo = value.Copy();
                    grdCustomInfo.DataSource = this.dtCustomInfo;
                }
            }
        }


        public CustomInfo()
        {
            InitializeComponent();

            //ButtonItemIconHelper.InitRibbonBar(this.ribbonBar1);
        }

        public CustomInfo(ClientAppBase app): base(app)
        {
            InitializeComponent();

            ButtonItemIconHelper.InitRibbonBar(this.ribbonBar1);
        }

        private void sideBar1_Click(object sender, EventArgs e)
        {

        }

        private void bubbleButton1_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
        {

        }

        private void panelEx3_Click(object sender, EventArgs e)
        {

        }

        private void crdViewCustomInfo_CustomDrawCardFieldValue(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.FieldName == DBEntityCustomInfo.FieldName.CSTATE)
            {
                Rectangle r = e.Bounds;
                string sText = DBEntityCustomInfo.ENUM_CSTATE.EnumStrToChineseStr(e.CellValue.ToString());
                e.Style.DrawString(e.Graphics, sText, r);
                e.Handled = true;
            }else if (e.Column.FieldName == DBEntityCustomInfo.FieldName.CBIRTHDAYTYPE){
                Rectangle r = e.Bounds;
                string sText = DBEntityCustomInfo.ENUM_CBIRTHDAYTYPE.EnumStrToChineseStr(e.CellValue.ToString());
                e.Style.DrawString(e.Graphics, sText, r);
                e.Handled = true;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (cvCustomInfo.FocusedRowHandle < 0)
            {
                MsgBox.MsgInfo("请选择正确的会员信息。");
                return;
            }
            DataRow drCustomInfo = cvCustomInfo.GetDataRow(cvCustomInfo.FocusedRowHandle);
            DBEntityCustomInfo customInfo = new DBEntityCustomInfo(drCustomInfo);

            frmCustomInfoAdd frmCustom = new frmCustomInfoAdd(customInfo);
            if (frmCustom.ShowDialog() == DialogResult.OK)
            {
                DataSet dsCustomInfo = new DataSet();
                string error = string.Empty;

                if (!BussinessProxyManager.Instance.QueryCustomerID(customInfo.SALONID, out dsCustomInfo, out error))
                {
                    MsgBox.MsgInfo(error);
                    return;
                }
                cvCustomInfo.BeginUpdate();
                dtCustomInfo = dsCustomInfo.Tables[0].Copy();
                grdCustomInfo.DataSource = dtCustomInfo;
                cvCustomInfo.EndUpdate();
            }
            
        }

        private void dockSite7_Click(object sender, EventArgs e)
        {

        }
    }
}
